@page "/organization-memberships/{OrganizationId:guid?}"
@using EventHub.Admin.Organizations.Memberships
@using EventHub.Admin.Permissions
@using Microsoft.AspNetCore.Authorization
@inherits EventHubComponentBase
@attribute [Authorize(EventHubPermissions.Organizations.Memberships.Default)]
@inject IOrganizationMembershipAppService OrganizationMembershipAppService

<Card>
    <CardHeader>
        @* ************************* HEADER ************************* *@
        <h2>
            @L["OrganizationMemberships"]
            @if (OrganizationId.HasValue && !OrganizationName.IsNullOrWhiteSpace())
            {
                <span> (@OrganizationName)</span>
            }
        </h2>
    </CardHeader>

    @* ************************* SEARCH ************************* *@
    <CardBody>
        <div id="FilterSection" class="mt-3 ml-2">
            <Row>
                <Column ColumnSize="ColumnSize.Is6">
                    <Field>
                        <FieldLabel>@L["OrganizationName"]</FieldLabel>
                        <TextEdit TValue="string" KeyPress="OnKeyPress" @bind-Text="@OrganizationName"/>
                    </Field>
                </Column>

                <Column ColumnSize="ColumnSize.Is6">
                    <Field>
                        <FieldLabel>@L["UserName"]</FieldLabel>
                        <TextEdit TValue="string" KeyPress="OnKeyPress" @bind-Text="@Filter.UserName"/>
                    </Field>
                </Column>
            </Row>
        </div>

        @* ************************* DATA GRID ************************* *@
        <DataGrid TItem="OrganizationMemberDto"
                  Data="OrganizationMemberList"
                  ReadData="OnDataGridReadAsync"
                  TotalItems="TotalCount"
                  ShowPager="true"
                  PageSize="PageSize"
                  Sortable="false">
            <DataGridColumns>
                <DataGridColumn TItem="OrganizationMemberDto"
                                Field="OrganizationName"
                                Caption="@L["OrganizationName"]">
                </DataGridColumn>
                <DataGridColumn TItem="OrganizationMemberDto"
                                Field="UserName"
                                Caption="@L["UserName"]">
                </DataGridColumn>

                <DataGridColumn TItem="OrganizationMemberDto"
                                Field="Email"
                                Caption="@L["Email"]">
                </DataGridColumn>

                <DataGridColumn TItem="OrganizationMemberDto"
                                Field="Name"
                                Caption="@L["Name"]">
                </DataGridColumn>

                <DataGridColumn TItem="OrganizationMemberDto"
                                Field="Surname"
                                Caption="@L["Surname"]">
                </DataGridColumn>
            </DataGridColumns>
        </DataGrid>
    </CardBody>
</Card>